function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
// import { eventHandler } from '../interface';
var listenerReg = /^on[A-Z]+/;
var propsReg = /^props([A-Z]+)/;

//合并事件
export function mergeEventHandler() {
  var s = {};
  return function handleMerge(n, isReplace) {
    if (isReplace) {
      s = merge({}, n);
      return handleMerge;
    }
    if (!n) return converArraytoFunc(s);else {
      s = merge(s, n);
      return handleMerge;
    }
  };
  function merge() {
    var s = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
    var n = arguments.length > 1 ? arguments[1] : undefined;
    if (!n) return s;
    Object.keys(n).forEach(function (key) {
      if (key === 'children' && n.children) {
        s.children = merge(s.children || {}, n.children);
      } else if (listenerReg.test(key) && typeof n[key] === 'function') {
        if (s[key]) {
          if (Array.isArray(s[key])) s[key].push(n[key]);else s[key] = [s[key], n[key]];
        } else s[key] = n[key];
      } else if (_typeof(n[key]) === 'object') {
        s[key] = merge(s[key], n[key]);
      } else {
        s[key] = n[key];
      }
    });
    return s;
  }
  function converArraytoFunc(s) {
    var x = {};
    Object.keys(s).forEach(function (key) {
      if (listenerReg.test(key)) {
        if (Array.isArray(s[key])) {
          x[key] = function () {
            var _arguments = arguments;
            s[key].forEach(function (item) {
              return item.apply(void 0, _toConsumableArray(_arguments));
            });
          };
        } else {
          x[key] = s[key];
        }
      } else if (propsReg.test(key)) {
        var pkey = key.replace(propsReg, function (match, $1) {
          return $1.toLowerCase();
        });
        x[pkey] = s[key];
      } else {
        x[key] = converArraytoFunc(s[key]);
      }
    });
    return x;
  }
}